/*
 * Created on May 15, 2004
 */
package dk.aiszone.lang.utils;

/**
 * A set of helper methods for <code>Arrays</code>.
 * 
 * @author <a href="mailto:ais@mail.dk">Ais</a>
 * @since 1.0
 * @version 1.0
 */
public class ArrayUtils {

    /**
     * Converts the supplied <code>Array</code> of <code>Objects</code> to a <code>String</code>.<br>
     * The <code>Objects</code> to return as a &quot;,&quot; seperated <code>String</code>.
     * 
     * @param array
     *            The <code>Array</code> of convert
     * @return The <code>String</code> representation of the <code>Array</code> contents.
     */
    public static String arrayToString(Object[] array) {
        return arrayToString(array, ", ");
    }

    /**
     * Converts the supplied <code>Array</code> of <code>Objects</code> to a <code>String</code>.<br>
     * The <code>Objects</code> to return as a seperated <code>String</code> - where the seperator determined by the argument.
     * 
     * @param array
     *            The <code>Array</code> of convert
     * @param separator
     *            The seperator to use
     * @return The <code>String</code> representation of the <code>Array</code> contents.
     */
    public static String arrayToString(Object[] array, String separator) {
        if (array == null || array.length == 0) {
            return "";
        }

        StringBuffer buf = new StringBuffer();
        buf.append(array[0]);

        for (int index = 1; index < array.length; index++) {
            buf.append(separator);
            buf.append(array[index]);
        }

        return buf.toString();
    }
}